#include <stdio.h>
#include <time.h>

/*
 * 32位words
 */

void tm1()
{
	struct tm t;
	time_t unix_time;

	unix_time = time(NULL);

	localtime_r(&unix_time, &t);

	printf("Year: %d\n", t.tm_year+1990);
	printf("Month: %d\n", t.tm_mon);
	printf("Day: %d\n", t.tm_mday);
	printf("Hour: %d\n", t.tm_hour);
	printf("Minutes: %d\n", t.tm_min);
	printf("Seconds: %d\n", t.tm_sec);
}

void tm2()
{
	struct tm t;
	time_t unix_time;
	int i=0, tmp=0;

	unix_time = time(NULL);

	localtime_r(&unix_time, &t);

	for (i = 0; i < 9; i++) {
		tmp = ((int*)&t)[i];
		printf("0x%08X (%d)\n", tmp, tmp);
	}

}

int main()
{
	tm1();
	tm2();

	return 0;
}

#if 0
/*
 * intel
 */
00000000000011a9 <tm1>:
    11a9:	f3 0f 1e fa          	endbr64 
    11ad:	55                   	push   %rbp
    11ae:	48 89 e5             	mov    %rsp,%rbp
    11b1:	48 83 ec 50          	sub    $0x50,%rsp
    11b5:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    11bc:	00 00 
    11be:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    11c2:	31 c0                	xor    %eax,%eax
    11c4:	bf 00 00 00 00       	mov    $0x0,%edi
    11c9:	e8 e2 fe ff ff       	callq  10b0 <time@plt>	// time(NULL)
    11ce:	48 89 45 b8          	mov    %rax,-0x48(%rbp)
    11d2:	48 8d 55 c0          	lea    -0x40(%rbp),%rdx		// tm
    11d6:	48 8d 45 b8          	lea    -0x48(%rbp),%rax		// unix_time
    11da:	48 89 d6             	mov    %rdx,%rsi
    11dd:	48 89 c7             	mov    %rax,%rdi
    11e0:	e8 9b fe ff ff       	callq  1080 <localtime_r@plt>	// localtime(rdi, rsi)
    11e5:	8b 45 d4             	mov    -0x2c(%rbp),%eax		// eax=(rbp-0x2c)	rbp-0x2c=tm-0x14=(rbp-0x40)-0x14
    11e8:	05 c6 07 00 00       	add    $0x7c6,%eax		// eax=(rbp-0x2c)+0x7c6
    11ed:	89 c6                	mov    %eax,%esi		// esi=(rbp-0x2c)+0x7c6
    11ef:	48 8d 3d 0e 0e 00 00 	lea    0xe0e(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>	rdi=2004
    11f6:	b8 00 00 00 00       	mov    $0x0,%eax
    11fb:	e8 a0 fe ff ff       	callq  10a0 <printf@plt>	// printf(rdi, esi)
    1200:	8b 45 d0             	mov    -0x30(%rbp),%eax		// tm-0x10
    1203:	89 c6                	mov    %eax,%esi
    1205:	48 8d 3d 02 0e 00 00 	lea    0xe02(%rip),%rdi        # 200e <_IO_stdin_used+0xe>
    120c:	b8 00 00 00 00       	mov    $0x0,%eax
    1211:	e8 8a fe ff ff       	callq  10a0 <printf@plt>
    1216:	8b 45 cc             	mov    -0x34(%rbp),%eax		// tm-0xc
    1219:	89 c6                	mov    %eax,%esi
    121b:	48 8d 3d f7 0d 00 00 	lea    0xdf7(%rip),%rdi        # 2019 <_IO_stdin_used+0x19>
    1222:	b8 00 00 00 00       	mov    $0x0,%eax
    1227:	e8 74 fe ff ff       	callq  10a0 <printf@plt>
    122c:	8b 45 c8             	mov    -0x38(%rbp),%eax		// tm-8
    122f:	89 c6                	mov    %eax,%esi
    1231:	48 8d 3d ea 0d 00 00 	lea    0xdea(%rip),%rdi        # 2022 <_IO_stdin_used+0x22>
    1238:	b8 00 00 00 00       	mov    $0x0,%eax
    123d:	e8 5e fe ff ff       	callq  10a0 <printf@plt>
    1242:	8b 45 c4             	mov    -0x3c(%rbp),%eax		// tm-4
    1245:	89 c6                	mov    %eax,%esi
    1247:	48 8d 3d de 0d 00 00 	lea    0xdde(%rip),%rdi        # 202c <_IO_stdin_used+0x2c>
    124e:	b8 00 00 00 00       	mov    $0x0,%eax
    1253:	e8 48 fe ff ff       	callq  10a0 <printf@plt>
    1258:	8b 45 c0             	mov    -0x40(%rbp),%eax		// tm
    125b:	89 c6                	mov    %eax,%esi
    125d:	48 8d 3d d5 0d 00 00 	lea    0xdd5(%rip),%rdi        # 2039 <_IO_stdin_used+0x39>
    1264:	b8 00 00 00 00       	mov    $0x0,%eax
    1269:	e8 32 fe ff ff       	callq  10a0 <printf@plt>
    126e:	90                   	nop
    126f:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
    1273:	64 48 33 04 25 28 00 	xor    %fs:0x28,%rax
    127a:	00 00 
    127c:	74 05                	je     1283 <tm1+0xda>
    127e:	e8 0d fe ff ff       	callq  1090 <__stack_chk_fail@plt>
    1283:	c9                   	leaveq 
    1284:	c3                   	retq   

0000000000001285 <tm2>:
    1285:	f3 0f 1e fa          	endbr64 
    1289:	55                   	push   %rbp
    128a:	48 89 e5             	mov    %rsp,%rbp
    128d:	48 83 ec 50          	sub    $0x50,%rsp
    1291:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    1298:	00 00 
    129a:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    129e:	31 c0                	xor    %eax,%eax
    12a0:	c7 45 b0 00 00 00 00 	movl   $0x0,-0x50(%rbp)	// (rbp-0x50)=0
    12a7:	c7 45 b4 00 00 00 00 	movl   $0x0,-0x4c(%rbp)	// (rbp-0x4c)=0
    12ae:	bf 00 00 00 00       	mov    $0x0,%edi	// edi=0
    12b3:	e8 f8 fd ff ff       	callq  10b0 <time@plt>	// time(0)
    12b8:	48 89 45 b8          	mov    %rax,-0x48(%rbp)	// (rbp-0x48)=time return value
    12bc:	48 8d 55 c0          	lea    -0x40(%rbp),%rdx	
    12c0:	48 8d 45 b8          	lea    -0x48(%rbp),%rax
    12c4:	48 89 d6             	mov    %rdx,%rsi
    12c7:	48 89 c7             	mov    %rax,%rdi
    12ca:	e8 b1 fd ff ff       	callq  1080 <localtime_r@plt>	// localtime(rdi, rsi)
    12cf:	c7 45 b0 00 00 00 00 	movl   $0x0,-0x50(%rbp)		// (rbp-0x50)=0 ==> x=0
    12d6:	eb 36                	jmp    130e <tm2+0x89>		// for x
    12d8:	8b 45 b0             	mov    -0x50(%rbp),%eax		
    12db:	48 98                	cltq   				// rax=x
    12dd:	48 8d 14 85 00 00 00 	lea    0x0(,%rax,4),%rdx	// rdx=x*4+0x0
    12e4:	00 
    12e5:	48 8d 45 c0          	lea    -0x40(%rbp),%rax		// rax=rbp-0x40
    12e9:	48 01 d0             	add    %rdx,%rax		// rax=rbp-0x40+(x*4)
    12ec:	8b 00                	mov    (%rax),%eax		// eax=(rbp-0x40+(x*4))
    12ee:	89 45 b4             	mov    %eax,-0x4c(%rbp)		// (rbp-0x4c)=(rbp-0x40+(x*4))
    12f1:	8b 55 b4             	mov    -0x4c(%rbp),%edx		// edx=(rbp-0x40+(x*4))
    12f4:	8b 45 b4             	mov    -0x4c(%rbp),%eax		// eax=(rbp-0x40+(x*4))
    12f7:	89 c6                	mov    %eax,%esi		// esi=(rbp-0x40+(x*4))
    12f9:	48 8d 3d 46 0d 00 00 	lea    0xd46(%rip),%rdi        # 2046 <_IO_stdin_used+0x46>
    1300:	b8 00 00 00 00       	mov    $0x0,%eax
    1305:	e8 96 fd ff ff       	callq  10a0 <printf@plt>
    130a:	83 45 b0 01          	addl   $0x1,-0x50(%rbp)		// x++
    130e:	83 7d b0 08          	cmpl   $0x8,-0x50(%rbp)		// x-0x8
    1312:	7e c4                	jle    12d8 <tm2+0x53>		// for x
    1314:	90                   	nop
    1315:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
    1319:	64 48 33 04 25 28 00 	xor    %fs:0x28,%rax
    1320:	00 00 
    1322:	74 05                	je     1329 <tm2+0xa4>
    1324:	e8 67 fd ff ff       	callq  1090 <__stack_chk_fail@plt>
    1329:	c9                   	leaveq 
    132a:	c3                   	retq   

000000000000132b <main>:
    132b:	f3 0f 1e fa          	endbr64 
    132f:	55                   	push   %rbp
    1330:	48 89 e5             	mov    %rsp,%rbp
    1333:	90                   	nop
    1334:	5d                   	pop    %rbp
    1335:	c3                   	retq   
    1336:	66 2e 0f 1f 84 00 00 	nopw   %cs:0x0(%rax,%rax,1)
    133d:	00 00 00 

/*
 * arm
 */
00000000004005fc <tm1>:
  4005fc:	a9bb7bfd 	stp	x29, x30, [sp, #-80]!
  400600:	910003fd 	mov	x29, sp
  400604:	d2800000 	mov	x0, #0x0                   	// #0
  400608:	97ffffaa 	bl	4004b0 <time@plt>		// time(x0)
  40060c:	f9000ba0 	str	x0, [x29, #16]
  400610:	910063a1 	add	x1, x29, #0x18
  400614:	910043a0 	add	x0, x29, #0x10
  400618:	97ffffa2 	bl	4004a0 <localtime_r@plt>	// localtime(x0, x1)
  40061c:	b9402fa0 	ldr	w0, [x29, #44]
  400620:	111f1801 	add	w1, w0, #0x7c6
  400624:	90000000 	adrp	x0, 400000 <_init-0x468>	
  400628:	911f2000 	add	x0, x0, #0x7c8
  40062c:	97ffffb1 	bl	4004f0 <printf@plt>
  400630:	b9402ba1 	ldr	w1, [x29, #40]
  400634:	90000000 	adrp	x0, 400000 <_init-0x468>
  400638:	911f6000 	add	x0, x0, #0x7d8
  40063c:	97ffffad 	bl	4004f0 <printf@plt>
  400640:	b94027a1 	ldr	w1, [x29, #36]
  400644:	90000000 	adrp	x0, 400000 <_init-0x468>
  400648:	911fa000 	add	x0, x0, #0x7e8
  40064c:	97ffffa9 	bl	4004f0 <printf@plt>
  400650:	b94023a1 	ldr	w1, [x29, #32]
  400654:	90000000 	adrp	x0, 400000 <_init-0x468>
  400658:	911fe000 	add	x0, x0, #0x7f8
  40065c:	97ffffa5 	bl	4004f0 <printf@plt>
  400660:	b9401fa1 	ldr	w1, [x29, #28]
  400664:	90000000 	adrp	x0, 400000 <_init-0x468>
  400668:	91202000 	add	x0, x0, #0x808
  40066c:	97ffffa1 	bl	4004f0 <printf@plt>
  400670:	b9401ba1 	ldr	w1, [x29, #24]
  400674:	90000000 	adrp	x0, 400000 <_init-0x468>
  400678:	91206000 	add	x0, x0, #0x818
  40067c:	97ffff9d 	bl	4004f0 <printf@plt>
  400680:	d503201f 	nop
  400684:	a8c57bfd 	ldp	x29, x30, [sp], #80
  400688:	d65f03c0 	ret

000000000040068c <tm2>:
  40068c:	a9ba7bfd 	stp	x29, x30, [sp, #-96]!
  400690:	910003fd 	mov	x29, sp
  400694:	b9005fbf 	str	wzr, [x29, #92]
  400698:	b9005bbf 	str	wzr, [x29, #88]
  40069c:	d2800000 	mov	x0, #0x0                   	// #0
  4006a0:	97ffff84 	bl	4004b0 <time@plt>
  4006a4:	f9000fa0 	str	x0, [x29, #24]
  4006a8:	910083a1 	add	x1, x29, #0x20
  4006ac:	910063a0 	add	x0, x29, #0x18
  4006b0:	97ffff7c 	bl	4004a0 <localtime_r@plt>
  4006b4:	b9005fbf 	str	wzr, [x29, #92]
  4006b8:	1400000f 	b	4006f4 <tm2+0x68>
  4006bc:	b9805fa0 	ldrsw	x0, [x29, #92]
  4006c0:	d37ef400 	lsl	x0, x0, #2
  4006c4:	910083a1 	add	x1, x29, #0x20
  4006c8:	8b000020 	add	x0, x1, x0
  4006cc:	b9400000 	ldr	w0, [x0]
  4006d0:	b9005ba0 	str	w0, [x29, #88]
  4006d4:	90000000 	adrp	x0, 400000 <_init-0x468>
  4006d8:	9120a000 	add	x0, x0, #0x828
  4006dc:	b9405ba2 	ldr	w2, [x29, #88]
  4006e0:	b9405ba1 	ldr	w1, [x29, #88]
  4006e4:	97ffff83 	bl	4004f0 <printf@plt>
  4006e8:	b9405fa0 	ldr	w0, [x29, #92]
  4006ec:	11000400 	add	w0, w0, #0x1
  4006f0:	b9005fa0 	str	w0, [x29, #92]
  4006f4:	b9405fa0 	ldr	w0, [x29, #92]
  4006f8:	7100201f 	cmp	w0, #0x8
  4006fc:	54fffe0d 	b.le	4006bc <tm2+0x30>
  400700:	d503201f 	nop
  400704:	a8c67bfd 	ldp	x29, x30, [sp], #96
  400708:	d65f03c0 	ret

000000000040070c <main>:
  40070c:	d503201f 	nop
  400710:	d65f03c0 	ret
  400714:	00000000 	.inst	0x00000000 ; undefined


#endif

